AnnieRoot.ui=AnnieRoot.ui||{};
AnnieRoot.ui.GameTimersManager=function(){
	var s = this;
	annie.Sprite.call(s);
	/*_a2x_need_start*/s.num0=null;s.num1=null;s.timeBar=null;/*_a2x_need_end*/
	annie.initRes(s,"ui","GameTimersManager");
	//your code here
	var timer = new annie.Timer(1000);
	s.addEventListener(annie.Event.ADD_TO_STAGE, function (e) {
		// timer.start();
		if (AnnieRoot.gameGlobalData.initGameData && AnnieRoot.gameGlobalData.initGameData.time) {
			s.totalTimes = parseInt(AnnieRoot.gameGlobalData.initGameData.time);//获取游戏时间;
			s.serviceCallBackTimes = parseInt(AnnieRoot.gameGlobalData.initGameData.time);//获取游戏时间;
		}
		s.updateTimesNum(s.totalTimes);
	});
	timer.addEventListener(annie.Event.TIMER, function (e) {
		if (s.totalTimes == 0) {
			annie.globalDispatcher.dispatchEvent('throwRopeEvent', {status: 'timeOut'});//20秒如果用户没有按抛出绳子按钮，自动抛出
		} else if (s.totalTimes > 0) {
			s.totalTimes--;
			s.timeBar.bar_mc.scaleX = s.timeBar.bar_mc.scaleX - (1 / s.serviceCallBackTimes);
			s.updateTimesNum(s.totalTimes);
		}
	});
	/*初始化是在游戏时间*/
	annie.globalDispatcher.addEventListener('setGameTime', function (e) {
		AnnieRoot.gameGlobalData.initGameData.time=20;
		s.totalTimes = parseInt(AnnieRoot.gameGlobalData.initGameData.time);//获取游戏时间;
		s.updateTimesNum(s.totalTimes);
		s.timeBar.bar_mc.scaleX = 1;
		// s.timeBar.gotoAndStop(s.totalTimes + 1);
	});
	/*停止倒计时*/
	annie.globalDispatcher.addEventListener('stopTimerEvent', function (e) {
		timer.stop();
	});
	/*重设倒计时*/
	annie.globalDispatcher.addEventListener('resetTimerEvent', function (e) {
		AnnieRoot.gameGlobalData.initGameData.time=20;
		s.totalTimes = parseInt(AnnieRoot.gameGlobalData.initGameData.time);//获取游戏时间;
		s.timeBar.bar_mc.scaleX = 1;
		s.updateTimesNum(s.totalTimes);
		s.resetTimer();
		timer.start();
	})
};
annie.A2xExtend(AnnieRoot.ui.GameTimersManager,annie.Sprite);
AnnieRoot.ui.GameTimersManager.prototype.serviceCallBackTimes = 20;
AnnieRoot.ui.GameTimersManager.prototype.totalTimes = 20;
/*重设时间*/
AnnieRoot.ui.GameTimersManager.prototype.resetTimer = function () {
	var s = this;
	AnnieRoot.gameGlobalData.initGameData.time=20;
	s.totalTimes = parseInt(AnnieRoot.gameGlobalData.initGameData.time);//获取游戏时间;
	s.updateTimesNum(s.totalTimes);
	// s.timeBar.gotoAndStop(s.totalTimes + 1);
};
AnnieRoot.ui.GameTimersManager.prototype.updateTimesNum = function (time) {
	var s = this,
		numStr = time.toString();
	if (time >= 10) {
		s.num0.gotoAndStop(parseInt(numStr.charAt(1)) + 1);
		s.num1.gotoAndStop(parseInt(numStr.charAt(0)) + 1);
	} else {
		s.num0.gotoAndStop(parseInt(numStr.charAt(0)) + 1);
		s.num1.gotoAndStop(1);
	}
	// s.timeBar.gotoAndStop(time + 1);
	// console.log('num:' + numStr, numStr.charAt(1));
};
